import {getListData,addBanner,deleteOneBanner,updateOneBanner} from '../apis/banner.js'
import {message} from 'antd'
export default {
    state:{
        menuList:[]
    },
    effects:{
        *menuListInit ({payload},{call,put}){
            const res=yield call(getListData)
            // console.log(res.message);
            yield put({
                type:'initMenuList',
                payload:res.message
            })
        },
        *addBannerLnit({payload},{call,put}){
            const result=yield call(addBanner,payload)
            if(result.code==200){
                console.log(result);
                message.success('新增成功')
            }else{
                message.error('新增失败')
            }
            const res=yield call(getListData)
            yield put({
                type:'initMenuList',
                payload:res.message
            })
        },
        *deleteBannerInit({payload},{call,put}){
            const result=yield call(deleteOneBanner,payload)
            if(result.code==200){
                console.log(result);
                message.success('删除成功')
            }else{
                message.error('删除失败')
            }
            const res=yield call(getListData)
            yield put({
                type:'initMenuList',
                payload:res.message
            })
        },
        *updateBannerInit({payload},{call,put}){
            const result=yield call(updateOneBanner,payload)
            if(result.code==200){
                console.log(result);
                message.success('修改成功')
            }else{
                message.error('修改失败')
            }
            const res=yield call(getListData)
            yield put({
                type:'initMenuList',
                payload:res.message
            })
        },
    },
    reducers:{
        initMenuList(state,action){
            state.menuList=action.payload
        }
    }
}